﻿using IServices;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Linq;
using YL.Core.Dto;
using YL.Core.Entity;
using YL.Core.Entity.Fluent.Validation;
using YL.NetCore.Attributes;
using YL.NetCore.NetCoreApp;
using YL.Utils.Extensions;
using YL.Utils.Pub;
using YL.Utils.Table;

namespace KopSoftWms.Controllers
{
    public class ReportController : BaseController
    {
        private IWms_inventoryServices _inventoryServices;
        private IWms_stockinServices _stockInServices;

        public ReportController(IWms_inventoryServices inventoryServices, IWms_stockinServices stockInServices)
        {
            this._inventoryServices = inventoryServices;
            this._stockInServices = stockInServices;
        }

        [HttpGet]
        [CheckMenu]
        public IActionResult Index()
        {

            return View();
        }

        [HttpGet]
        [CheckMenu]
        public IActionResult NewStockInfo(string dateMin, string dateMax, int stockType)
        {

            if (string.IsNullOrEmpty(dateMax))
            {
                dateMax = DateTime.Now.ToString("yyyy-MM-dd");
            }

            if (string.IsNullOrEmpty(dateMin))
            {
                dateMin = dateMax;
            }

            var stockInfo = this._stockInServices.GetTableStockIn(dateMin, dateMax, stockType);

            string pageTitle = "入库信息";
            if (stockType == 1)
            {
                pageTitle = "出库信息";
            }

            ViewData["Title"] = stockInfo.Title;
            ViewData["Data"] = stockInfo.DataList;
            ViewData["TitleBm"] = stockInfo.TitleBm;
            ViewData["dateMin"] = dateMin;
            ViewData["dateMax"] = dateMax;
            ViewData["PageTitle"] = pageTitle;
            ViewData["stockType"] = stockType;

            return View();
        }

        [HttpGet]
        [CheckMenu]
        public IActionResult NewStockIn(string dateMin, string dateMax)
        {
            if (string.IsNullOrEmpty(dateMin))
            {
                dateMin = DateTime.Now.ToString("yyyy-MM-01");
            }

            if (string.IsNullOrEmpty(dateMax))
            {
                dateMax = DateTime.Now.ToString("yyyy-MM-dd");
            }

            var bootParams = new PubParams.StockInSummaryBootstrapParams();
            bootParams.datemin = dateMin;
            bootParams.datemax = dateMax;
            bootParams.StockType = 0; // 入库



            ViewBag.inSumInfo = this._stockInServices.GetSumInventory(bootParams);
            ViewBag.datemin = dateMin;
            ViewBag.datemax = dateMax;
            return View();
        }


        [HttpGet]
        [CheckMenu]
        public IActionResult NewStockOut(string dateMin, string dateMax)
        {
            if (string.IsNullOrEmpty(dateMin))
            {
                dateMin = DateTime.Now.ToString("yyyy-MM-01");
            }

            if (string.IsNullOrEmpty(dateMax))
            {
                dateMax = DateTime.Now.ToString("yyyy-MM-dd");
            }

            var bootParams = new PubParams.StockInSummaryBootstrapParams();
            bootParams.datemin = dateMin;
            bootParams.datemax = dateMax;
            bootParams.StockType = 1; // 出库
            ViewBag.outSumInfo = this._stockInServices.GetSumInventory(bootParams);
            ViewBag.datemin = dateMin;
            ViewBag.datemax = dateMax;
            return View();
        }

        [HttpGet]
        public IActionResult Details(string dateMin, string dateMax, int stockType, string materialId)
        {
            ViewBag.stockType = stockType;
            ViewBag.dateMin = dateMin;
            ViewBag.dateMax = dateMax;
            ViewBag.materialId = materialId;
            if (stockType == 0)
            {
                ViewBag.stockTypeName = "入库";
            }
            else
            {
                ViewBag.stockTypeName = "出库";
            }
            return View();
        }

        [HttpGet]
        [CheckMenu]
        public IActionResult WareInfo()
        {
            ViewBag.wareInfo = this._stockInServices.GetStockInfoHtml();
            return View();
        }
    }
}